package o;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.ButtonFactory;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.wishwall.widget.dldbtn.WishWallDldButton.d;
import java.lang.ref.WeakReference;
import o.dby.e;
import o.ddq.f;

public class dej implements ckc, ckb {
    private ckc ˋ;
    protected Context ॱ;

    static class a implements e {
        private WeakReference<dej> ˊ;
        private DownloadButton ˋ;
        private cke ˎ;
        private Context ˏ;
        private BaseDistCardBean ॱ;

        public a(dej o_dej, Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
            this.ˊ = new WeakReference(o_dej);
            this.ˏ = context;
            this.ˋ = downloadButton;
            this.ॱ = baseDistCardBean;
            this.ˎ = o_cke;
        }

        public void ˋ(boolean z) {
            if (this.ˊ != null) {
                dej o_dej = (dej) this.ˊ.get();
                if (o_dej != null) {
                    o_dej.ॱ(this.ˏ, this.ˋ, this.ॱ, this.ˎ);
                }
            }
        }

        public void ॱ() {
        }
    }

    static class b {
        private static final Object ˊ = new byte[0];
        private static volatile b ˋ = null;
        private bnh ˎ = ((bnh) fho.ˏ().ˋ("DownloadEngine").ॱ(bnh.class));

        private b() {
        }

        public static b ॱ() {
            b bVar;
            synchronized (ˊ) {
                if (ˋ == null) {
                    ˋ = new b();
                }
                bVar = ˋ;
            }
            return bVar;
        }

        public void ˏ(String str) {
            SessionDownloadTask ˋ = ˋ(str);
            if (ˋ != null) {
                this.ˎ.ˊ(ˋ.ʾ());
            }
        }

        private SessionDownloadTask ˋ(String str) {
            for (SessionDownloadTask sessionDownloadTask : this.ˎ.ॱ()) {
                if (sessionDownloadTask.ˌ() != 9 && sessionDownloadTask.ˌ() != 10 && str.equals(sessionDownloadTask.ˊˊ())) {
                    return sessionDownloadTask;
                }
            }
            return null;
        }
    }

    public dej(Context context) {
        this.ॱ = context;
        this.ˋ = ButtonFactory.ˏ(DownloadButton.class, context);
        if (this.ˋ != null) {
            this.ˋ.ˎ(this);
        }
    }

    public ckg ˎ(BaseDistCardBean baseDistCardBean) {
        if (this.ˋ != null) {
            return this.ˋ.ˎ(baseDistCardBean);
        }
        return null;
    }

    public CharSequence ˋ(BaseDistCardBean baseDistCardBean, cke o_cke, CharSequence charSequence, TextView textView) {
        if (this.ˋ != null) {
            return this.ˋ.ˋ(baseDistCardBean, o_cke, charSequence, textView);
        }
        return null;
    }

    public ckd ˋ() {
        if (this.ˋ != null) {
            return this.ˋ.ˋ();
        }
        return null;
    }

    public ckd ˎ(int i, int i2) {
        if (this.ˋ != null) {
            return this.ˋ.ˎ(i, i2);
        }
        return null;
    }

    public void ˋ(DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        if (this.ˋ != null) {
            this.ˋ.ˋ(downloadButton, baseDistCardBean, o_cke);
        }
    }

    public void ˊ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        BaseDistCardBean ˏ = d.ˊ().ˏ();
        String ॱـ = ˏ == null ? null : ˏ.ॱـ();
        d.ˊ().ˋ(null);
        d.ˊ().ˏ(null);
        ॱ(baseDistCardBean.ॱـ(), ॱـ);
        dby ˏ2 = dby.ˏ(context.getString(f.ॱᐝ));
        ˏ2.ˋ(new a(this, context, downloadButton, baseDistCardBean, o_cke));
        ˏ2.ˎ(false);
        ˏ2.ˎ(context);
    }

    public void ॱ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        if (this.ˋ != null) {
            this.ˋ.ॱ(context, downloadButton, baseDistCardBean, o_cke);
            d.ˊ().ˋ(baseDistCardBean);
            d.ˊ().ˏ(baseDistCardBean.ˋ());
        }
    }

    public void ˎ(ckb o_ckb) {
    }

    public void ˋ(Context context, DownloadButton downloadButton, BaseDistCardBean baseDistCardBean, cke o_cke) {
        ˊ(context, downloadButton, baseDistCardBean, o_cke);
    }

    private void ॱ(String str, String str2) {
        if (!TextUtils.isEmpty(str)) {
            b.ॱ().ˏ(str);
            if (!TextUtils.isEmpty(str2) && !str.equals(str2)) {
                b.ॱ().ˏ(str2);
            }
        }
    }
}
